/* ************************************************************************************************

	Copyright (c) 2005-2006, IGR
	All Rights Reserved.
	Licensed under the Apache License version 2.0 or above.
	For more information on licensing, see:
        http://www.apache.org/licenses/


 ************************************************************************************************
 Objet GRID
 VERSION:0.85
 DATE:15/06/2006
 ************************************************************************************************
Init parameter in objPar (object of parameter):
same as grid parameter
*/

// *************************************
// CONSTRUCTOR
// *************************************

rialto.widget.GridTree=function (objPar){
    //PARAMETER
    objPar.type="Gridtreeview";
    objPar.switchable=false;
    objPar.sortable=false;
    objPar.lineHeight=23;
    //base constructor
    this.base = rialto.widget.AbstractComponent;    
    this.base(objPar);
    
    var oThis=this;
    
    //GRID
    this.grid=new rialto.widget.Grid(objPar);

    //Ovewrite print method
    this.grid.getInfoPrint =function(){
	    var obj=new Object;    	    
	    obj.strEntete=new String;
	    obj.strEntete=this.tabEntete.join("$");    
	    obj.tabEntete=this.tabEntete;    
	    obj.strEntete=rialto.string.formatHTTP(obj.strEntete);   
	    obj.titre=this.titrePrint;
	    obj.NBCOL=this.tabEntete.length;
	    obj.NbreLig=this.NbreLig;
	    /*Make a new array to print with for each line
	    	in the first row the value of the node  (store in the last cell of the array of this line)
	    	rest of the grid line values
	    */
	    var arrTemp=new Array;
	    for(var i=0;i<this.tabData.length;i++){
		    arrTemp[i]=new Array;
		    arrTemp[i][0]=this.tabData[i][this.NbreCol];
		    for(var j=1;j<this.tabData[i].length;j++){
			    arrTemp[i][j]=this.tabData[i][j];
		    }
	    }	    	    
	    obj.tabData=arrTemp;
	    return obj;
	}
    
    //TREE
    this.tree=new rialto.widget.Tree({name:'treeGrid',
    					top:'21',
    					left:'20',
    					width:parseInt(this.grid.tabTypeCol[0][1],10)-25,
    					height:objPar.height,
    					parent:this.grid.tableauEntete,
    					boolSelActive:false,
    					rootOpen:true,
    					withRoot:false,
    					withT:false,
    					position:'absolute'}
    				);
	this.tree.divExt.style.overflow='hidden';    				
	this.nodeRoot =this.tree.createAndAddNode(this.tree.id,{name:'nodeR',
															sText:'',
															sIcon:'',
															sIcon2:'',
															onclick:"",
															open:true,
															reload:false,
															url:"",
															typeInfo:''}
															);    				
	
 
	
	this.nodeRoot.oCiu=this;	
 }   
 
 
// TO ADD A NEW LINE WITH NODE 
rialto.widget.GridTree.prototype.addNodeLine =function(nodeP,text,open,tabData){ 

	var lineNode=new rialto.widget.LineNode(this,text,nodeP.open,tabData); 
	if(!nodeP){nodeP=this.nodeRoot}
	nodeP.icon = rialtoConfig.pathRialtoE + "images/imTreeview/pict_synthetik_off.gif";        
	nodeP.icon2 = rialtoConfig.pathRialtoE + "images/imTreeview/pict_synthetik_off.gif";        
	nodeP.addNode(lineNode.node);
	//nodeP.displayChilds(this.open);
	return lineNode.node;
	 	      	    	   	   
}

/************************************************************************************************
 Objet LINENODE
 VERSION:0.85
 DATE:16/03/2006
 ************************************************************************************************
Init parameter in objPar (object of parameter):
 parent:             GridTree parent 
 text:           	 text of the treenode 
 tabData			 value for this line in the grid
*************************************************************************************************/
	
rialto.widget.LineNode=function (parent,text,open,tabData){
	
	this.parent=parent;
	this.node =new rialto.widget.TreeNode({name:'node1',
					sText:text,
					sIcon:'images/imTreeview/puce.gif',
					sIcon2:'',
					onclick:"",
					open:open,
					reload:false,
					url:"",
					typeInfo:''});
					
	this.node.divText.className+=" ligne";
	
	if(!tabData){
		var tabData=new Array;
		for(var i=0;i<this.parent.grid.NbreCol;i++){
			tabData.push("");
		}
	}
	//ADD the node text value for printing
	tabData.push(this.node.text);
	this.node.indL=this.parent.grid.addOneLine(tabData);
	this.line=document.getElementById(this.parent.grid.id+"_LineTab_"+this.node.indL);
	this.node.oCiu=this;	


	var oThis=this;
	//Ovewrite methods of the treenode
	this.node.toggle=function(){
		traceExec("toggle",1);
		if (this.hasChild()){
		        if (this.open){
		            this.DIVCONTENU.style.display='none';
		            this.open=false;            
		        }
		        else{                                    
		            this.DIVCONTENU.style.display='block';	   	            
		            this.open=true;	                       
		        }          
		        this.displayChilds(this.open);
		        this.changeIcone();
		    }   
	}
	//To display or hide lines child
	this.node.displayChilds=function(isVisible){				
		if (this.hasChild()){
			for (var i=0;i<this.arrChildNode.length;i++){
				var node=this.arrChildNode[i];				
				var line=node.oCiu.line;				
				if(isVisible){	
					line.style.display='block';
				}
				else{
					line.style.display='none';
				}
				node.displayChilds(isVisible);
			}
		}
	}	
}    


rialto.widget.LineNode.prototype.getLine=function(indL){    
	return document.getElementById(this.parent.grid.id+"_LigneTab_"+this.node.indL);
}